import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;

import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class DOMCountElement {
	public static void main(String[] args) {
		try {
			BufferedReader bf = new BufferedReader(new InputStreamReader(
					System.in));
			File file = new File("empl.xml");
			DocumentBuilderFactory factory = DocumentBuilderFactory
					.newInstance();
			// Create the builder and parse the file
			Document doc = factory.newDocumentBuilder().parse(file);
			Element root = doc.getDocumentElement();
			NodeList rootlist = root.getChildNodes();

			
			
			
			
			
			
			
			
			
			System.out.print("Enter element name: ");
			String element = bf.readLine();
			NodeList nodes = doc.getElementsByTagName(element);
			System.out.println("xml Document Contains " + nodes.getLength()
					+ "  elements.");
		} catch (Exception ex) {
			System.out.println(ex);
		}
	}
}